<?php
class PrivilegeAction {
	public function index() {
		global $sMethod;
		$sMethod = 'index';
		if (! $_GET ['m']) {
			$_GET ['m'] = 'add';
		}
		$aList = Base::$oBase->Privilege_getList_model ();
		Base::$oBase->Template_assign ( 'url', './?' . Base::getSearch ( array ('m', 'name' ) ) );
		Base::$oBase->Template_assign ( 'list', $aList );
	}
	
	public function add() {
		if ($_POST ['cancel']) {
			Base::location ( './' . Base::getSearch ( array ('m', 'id' ) ) );
		} elseif ($_POST ['save'] || $_POST ['apply']) {
			$aInfo ['name'] = trim ( $_POST ['name'] );
			$aInfo ['desc'] = trim ( $_POST ['desc'] );
			$aInfo ['auth'] = trim ( $_POST ['auth'] );
			$aInfo ['method'] = Base::$oBase->Privilege_clean_model ( $_POST ['methods'] );
			$iPrivilegeId = Base::$oBase->Privilege_add_model ( $aInfo );
			if ($_POST ['save']) {
				Base::location ( './?' . Base::getSearch ( array ('m', 'id' ) ) );
			} else {
				Base::location ( './?' . Base::getSearch ( array ('id' => $iPrivilegeId ) ) );
			}
		}
		$this->index ();
	}
	
	public function edit() {
		if ($_POST ['cancel']) {
			Base::location ( './' . Base::getSearch ( array ('m', 'id' ) ) );
		} elseif ($_POST ['save'] || $_POST ['apply']) {
			$aInfo ['id'] = intval ( $_GET ['id'] );
			$aInfo ['name'] = trim ( $_POST ['name'] );
			$aInfo ['desc'] = trim ( $_POST ['desc'] );
			$aInfo ['auth'] = trim ( $_POST ['auth'] );
			$aInfo ['method'] = Base::$oBase->Privilege_clean_model ( $_POST ['methods'] );
			Base::$oBase->Privilege_edit_model ( $aInfo );
			if ($_POST ['save']) {
				Base::location ( './?' . Base::getSearch ( array ('m', 'id' ) ) );
			} else {
				Base::location ( './?' . Base::getSearch () );
			}
		}
		
		$aInfo = Base::$oBase->Privilege_get_model ( $_GET ['id'] );
		Base::$oBase->Template_assign ( 'info', $aInfo );
		$this->index ();
	}
	
	public function del() {
		if ($_POST ['confirm']) {
			Base::$oBase->Privilege_del_model ( $_GET ['id'] );
			Base::location ( './?' . Base::getSearch ( array ('m', 'id' ) ) );
		} elseif ($_POST ['cancel']) {
			Base::location ( './?' . Base::getSearch ( array ('m', 'id' ) ) );
		}
		$this->index ();
	}
}
?>
